package com.zyd.recyclerviewdemo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.zyd.recyclerviewdemo.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class SimpleRecyclerViewAdapter extends RecyclerView.Adapter {
    private LayoutInflater inflater;
    private List<String> listItem;
    //    private MyItemClickListener myItemClickListener;

    public SimpleRecyclerViewAdapter(Context context, List<String> listItem) {
        inflater = LayoutInflater.from(context);
        this.listItem = listItem;
    }//构造函数，传入数据

    //定义Viewholder
    class Viewholder extends RecyclerView.ViewHolder {
        private TextView Text;

        public Viewholder(View root) {
            super(root);
            Text = (TextView) root.findViewById(R.id.tv_item);
            //            root.setOnClickListener(new View.OnClickListener() {
            //                                        @Override
            //                                        public void onClick(View v) {
            //                                            if (myItemClickListener != null)
            //                                                myItemClickListener .onItemClick(v,getPosition());
            //                                        }
            //
            //                                    }//监听到点击就回调MainActivity的onItemClick函数
            //            );

        }


        public TextView getText() {
            return Text;
        }

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new Viewholder(inflater.inflate(R.layout.adapter_load_more, null));
    }//在这里把ViewHolder绑定Item的布局

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        Viewholder vh = (Viewholder) holder;
        vh.Text.setText((String) listItem.get(position));
    }//在这里绑定数据到ViewHolder里面

    @Override
    public int getItemCount() {
        return listItem.size();
    }//返回Item数目
    //
    //    public void setOnItemClickListener(MyItemClickListener listener) {
    //        myItemClickListener = listener;
    //    }//绑定MainActivity传进来的点击监听器
}
